﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace SkillSystem
{
    public class SkillManager : ISkillManager
    {
        private List<ISkillReceiver> skillReciviers = new List<ISkillReceiver>();

        private SkillInfo skillInfos;

        private SkillItemInfo skillItems;

        public void Init()
        {
            skillInfos = Resources.Load<SkillInfo>("ScriptableObject/SkillInfo");
            skillItems = Resources.Load<SkillItemInfo>("ScriptableObject/SkillItemInfo");
        }

        public SkillData GetSkillDataByID(int id)
        {
            for (int i = 0; i < skillInfos.Data.Count; i++)
            {
                if (skillInfos.Data[i].ID==id)
                {
                    return skillInfos.Data[i];
                } 
            }
            return null;
        }

        public SkillItemData GetSkillItemData(int id)
        {
            for (int i = 0; i < skillItems.Data.Count; i++)
            {
                if (skillItems.Data[i].ID == id)
                {
                    return skillItems.Data[i];
                }
            }
            return null;
        }
        

        /// <summary>
        /// 注册接收器
        /// </summary>
        /// <param name="receiver"></param>
        public void RegisterReceiver(ISkillReceiver receiver)
        {
            if (!skillReciviers.Contains(receiver))
            {
                skillReciviers.Add(receiver);
            }
        }

        /// <summary>
        /// 移除接收器
        /// </summary>
        /// <param name="receiver"></param>
        public void RemoveReceiver(ISkillReceiver receiver)
        {
            if (skillReciviers.Contains(receiver))
            {
                skillReciviers.Remove(receiver);
            }
        }
    }
}